library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.2 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.2 ✔ tibble 3.2.1
## ✔ lubridate 1.9.2 ✔ tidyr 1.3.0
## ✔ purrr 1.0.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggplot2)
#read our cleaned up data into the env
data_analytic <- readRDS("../../../data/interim/analytic2023_c1.rds")
#Injury deaths Raw(v135):Number of deaths due to injury per 100,000 population.
ggplot(data_analytic, aes(y = v005_rawvalue, x = v135_rawvalue))+
geom_point(color="green", alpha =0.5)+
geom_smooth()+
xlab(paste("Number of deaths due to injury per 100,000 population")) +
ylab("Preventable Hospital Stays")+
theme(panel.background = element_rect(fill = "black"),
plot.background = element_rect(fill = "black"),
panel.grid.major = element_line(color = "white", size = 0.1),
panel.grid.minor = element_line(color = "white", size = 0.05),
text = element_text(color = "white"))
## Warning: The `size` argument of `element_line()` is deprecated as of ggplot2 3.4.0.
## ℹ Please use the `linewidth` argument instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 131 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 131 rows containing missing values (`geom_point()`).
RACE ADUSTED
v135_xaxis_vars <- c("v135_race_hispanic", "v135_race_white", "v135_race_asian", "v135_race_aian", "v135_race_black")
v005_race_yaxis <- c("v005_race_hispanic","v005_race_white","v005_race_asian","v005_race_aian","v005_race_black")
# assuming the length of both vectors is the same
for(i in 1:length(v135_xaxis_vars)){
var_x <- v135_xaxis_vars[i]
var_y <- v005_race_yaxis[i]
va135byracegraph <-ggplot(data_analytic, aes_string(y = var_y, x = var_x))+
geom_point(color="green", alpha =0.5)+
geom_smooth()+
xlab(paste(var_x, ":Number of deaths due to injury per 100,000 population.")) +
ylab(paste(var_y, ":Preventable Hospital Stays"))+
theme(panel.background = element_rect(fill = "black"),
plot.background = element_rect(fill = "black"),
panel.grid.major = element_line(color = "white", size = 0.1),
panel.grid.minor = element_line(color = "white", size = 0.05),
text = element_text(color = "white"))
print(va135byracegraph)
}
## Warning: `aes_string()` was deprecated in ggplot2 3.0.0.
## ℹ Please use tidy evaluation idioms with `aes()`.
## ℹ See also `vignette("ggplot2-in-packages")` for more information.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 2407 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 2407 rows containing missing values (`geom_point()`).
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 195 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 195 rows containing missing values (`geom_point()`).
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 2877 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 2877 rows containing missing values (`geom_point()`).
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 2930 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 2930 rows containing missing values (`geom_point()`).
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 2031 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 2031 rows containing missing values (`geom_point()`).
#Suicide raw(v161):Number of deaths due to suicide per 100,000 population (age-adjusted).
ggplot(data_analytic, aes(y = v005_rawvalue, x = log(v161_rawvalue)))+
geom_point(color="green", alpha =0.5)+
geom_smooth()+
xlab(paste("Number of deaths due to suicide per 100,000 population (age-adjusted)")) +
ylab("Preventable Hospital Stays")+
theme(panel.background = element_rect(fill = "black"),
plot.background = element_rect(fill = "black"),
panel.grid.major = element_line(color = "white", size = 0.1),
panel.grid.minor = element_line(color = "white", size = 0.05),
text = element_text(color = "white"))
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 715 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 715 rows containing missing values (`geom_point()`).
v161_xaxis_vars <- c("v161_race_hispanic", "v161_race_white", "v161_race_asian", "v161_race_aian", "v161_race_black")
#Race: Hispanic
v005_race_yaxis <- c("v005_race_hispanic","v005_race_white","v005_race_asian","v005_race_aian","v005_race_black")
# assuming the length of both vectors is the same
for(i in 1:length(v135_xaxis_vars)){
var_x <- v135_xaxis_vars[i]
var_y <- v005_race_yaxis[i]
va135byracegraph <-ggplot(data_analytic, aes_string(y = paste0("log(",var_y,")"), x = paste0("log(",var_x,")")))+
geom_point(color="green", alpha =0.5)+
geom_smooth()+
xlab(paste(var_x, ":Number of deaths due to suicide per 100,000 population (age-adjusted)")) +
ylab(paste(var_y, ":Preventable Hospital Stays"))+
theme(panel.background = element_rect(fill = "black"),
plot.background = element_rect(fill = "black"),
panel.grid.major = element_line(color = "white", size = 0.1),
panel.grid.minor = element_line(color = "white", size = 0.05),
text = element_text(color = "white"))
print(va135byracegraph)
}
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 2407 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 2407 rows containing missing values (`geom_point()`).
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 195 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 195 rows containing missing values (`geom_point()`).
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 2877 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 2877 rows containing missing values (`geom_point()`).
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 2930 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 2930 rows containing missing values (`geom_point()`).
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 2031 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 2031 rows containing missing values (`geom_point()`).
#fire arm deaths raw(v148):Number of deaths due to firearms per 100,000 population.
ggplot(data_analytic, aes(y = v005_rawvalue, x = v148_rawvalue))+
geom_point(color="green", alpha =0.5)+
geom_smooth()+
xlab(paste("Number of deaths due to firearms per 100,000 population.")) +
ylab("Preventable Hospital Stays")+
theme(panel.background = element_rect(fill = "black"),
plot.background = element_rect(fill = "black"),
panel.grid.major = element_line(color = "white", size = 0.1),
panel.grid.minor = element_line(color = "white", size = 0.05),
text = element_text(color = "white"))
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 875 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 875 rows containing missing values (`geom_point()`).
v148_xaxis_vars <- c("v148_race_hispanic", "v148_race_white", "v148_race_asian", "v148_race_aian", "v148_race_black")
#Race: Hispanic
v005_race_yaxis <- c("v005_race_hispanic","v005_race_white","v005_race_asian","v005_race_aian","v005_race_black")
# assuming the length of both vectors is the same
for(i in 1:length(v135_xaxis_vars)){
var_x <- v135_xaxis_vars[i]
var_y <- v005_race_yaxis[i]
va135byracegraph <-ggplot(data_analytic, aes_string(y = var_y, x = var_x))+
geom_point(color="green", alpha =0.5)+
geom_smooth()+
xlab(paste(var_x, ":Number of deaths due to injury per 100,000 population.")) +
ylab(paste(var_y, ":Preventable Hospital Stays"))+
theme(panel.background = element_rect(fill = "black"),
plot.background = element_rect(fill = "black"),
panel.grid.major = element_line(color = "white", size = 0.1),
panel.grid.minor = element_line(color = "white", size = 0.05),
text = element_text(color = "white"))
print(va135byracegraph)
}
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 2407 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 2407 rows containing missing values (`geom_point()`).
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 195 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 195 rows containing missing values (`geom_point()`).
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 2877 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 2877 rows containing missing values (`geom_point()`).
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 2930 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 2930 rows containing missing values (`geom_point()`).
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 2031 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 2031 rows containing missing values (`geom_point()`).